package com.demo.java.gc;

public class MinorGCTest {
    public static final int _1M = 1024 * 1024;

    public static void main(String[] args) {
        /** eden: 8m, S0/S1: 1m */
        // -Xms30m -Xmx30m -Xmn10m -XX:+PrintGCDetails -XX:+PrintHeapAtGC
        LargeObject largeObject1 = new LargeObject(_1M * 1 / 2, "largeObject1");
        LargeObject largeObject2 = new LargeObject(_1M * 1, "largeObject2");
        LargeObject largeObject3 = new LargeObject(_1M * 2, "largeObject3");
        largeObject3 = null;
        LargeObject largeObject4 = new LargeObject(_1M * 3, "largeObject4");
        LargeObject largeObject5 = new LargeObject(_1M * 2, "largeObject5");
    }

    public static class LargeObject {
        private byte[] data;
        private String name;
        public LargeObject(int size, String name) {
            this.data = new byte[size];
            this.name = name;
            System.out.println("constructor large object: " + this.name + System.lineSeparator());
        }

        public String getName() {
            return name;
        }
    }
}
